window.addEventListener(
  "storage",
  function (event) {
    // console.log("key: " + event.newValue);

    var iframe = document.getElementsByName("main")[0];
    var mask = document.getElementsByName("mask")[0];
    var scope = $('div[ng-controller="controller"').scope();
    var cmd = event.newValue.substr(0, event.newValue.indexOf(","));
    switch (cmd) {
      case "home":
        scope.home();
        break;
      case "hide":
        scope.hideGlass();
        break;
    }
    if (cmd.indexOf("|") > -1) {
      var deviceId = cmd.substring(cmd.indexOf("|") + 1);
      scope.showDeviceInfo(deviceId);
    }
    if (cmd.indexOf("@") > -1) {
      var deviceId = cmd.substring(cmd.indexOf("@") + 1);
      scope.showIncidentInfo(deviceId);
    }
  },
  false
);
